package com.black.cat.jvm.classfile.constantpool.impl;


import com.black.cat.jvm.classfile.ClassReader;
import com.black.cat.jvm.classfile.constantpool.BaseConstantInfo;
import com.black.cat.jvm.classfile.constantpool.ConstantInfo;
import com.black.cat.jvm.classfile.constantpool.ConstantPool;
import com.black.cat.jvm.common.CommonValue;

/**
 * @Author blackcat
 * @create 2021/8/11 21:40
 * @version: 1.0
 * @description:表示方法句柄
 * CONSTANT_MethodHandle_info {
 * u1 tag;
 * u1 reference_kind;
 * u2 reference_index;
 * }
 */
public class ConstantInfoMethodHandle extends BaseConstantInfo implements ConstantInfo {
    private ConstantPool constantPool;
    private int referenceKind; // 1-9之间，方法句柄的类型
    private int referenceIndex;// 常量池索引

    public ConstantInfoMethodHandle(ConstantPool constantPool, ClassReader reader) {
        this.constantPool = constantPool;
        this.referenceKind = reader.nextU2ToInt();
        this.referenceIndex = reader.nextU2ToInt();
    }

    @Override
    public String getValue() {
        value = constantPool.getUtfStringByIndex(referenceKind) + "-" + constantPool.getUtfStringByIndex(referenceIndex);
        return super.getValue();
    }

    @Override
    public int getTag() {
        return CommonValue.CONSTANT_POOL_TAG_METHOD_HANDLE;
    }

}
